From f38e3b431b2f8562218758044c4486fe8da0e6dd Mon Sep 17 00:00:00 2001 From: Ewan Mellor Date: Fri, 23 Mar 2007 13:27:29 +0000 Subject: [PATCH] Add a last_updated field to every metrics class. Signed-off-by: Ewan Mellor --- docs/xen-api/xenapi-datamodel.tex | 198 ++++++++++++++++++++ tools/libxen/include/xen_host_metrics.h | 8 + tools/libxen/include/xen_pif_metrics.h | 8 + tools/libxen/include/xen_vbd_metrics.h | 8 + tools/libxen/include/xen_vif_metrics.h | 8 + tools/libxen/include/xen_vm_guest_metrics.h | 8 + tools/libxen/include/xen_vm_metrics.h | 8 + tools/libxen/src/xen_host_metrics.c | 21 ++- tools/libxen/src/xen_pif_metrics.c | 21 ++- tools/libxen/src/xen_vbd_metrics.c | 21 ++- tools/libxen/src/xen_vif_metrics.c | 21 ++- tools/libxen/src/xen_vm_guest_metrics.c | 21 ++- tools/libxen/src/xen_vm_metrics.c | 21 ++- tools/libxen/test/test_bindings.c | 5 + tools/python/xen/xend/XendAPI.py | 86 ++++----- tools/python/xen/xend/XendPIFMetrics.py | 4 +- tools/python/xen/xend/XendVMMetrics.py | 2 + 17 files changed, 417 insertions(+), 52 deletions(-) diff --git a/docs/xen-api/xenapi-datamodel.tex b/docs/xen-api/xenapi-datamodel.tex index 4a11ef0d9b..4d414e69ba 100644 --- a/docs/xen-api/xenapi-datamodel.tex +++ b/docs/xen-api/xenapi-datamodel.tex @@ -3983,6 +3983,7 @@ $\mathit{RO}_\mathit{run}$ & {\tt uuid} & string & unique identifier/object ref $\mathit{RO}_\mathit{run}$ & {\tt memory/actual} & int & Guest's actual memory (bytes) \\ $\mathit{RO}_\mathit{run}$ & {\tt VCPUs/number} & int & Current number of VCPUs \\ $\mathit{RO}_\mathit{run}$ & {\tt VCPUs/utilisation} & (int $\rightarrow$ float) Map & Utilisation for all of guest's current VCPUs \\ +$\mathit{RO}_\mathit{run}$ & {\tt last\_updated} & datetime & Time at which this information was last updated \\ \hline \end{longtable} \subsection{RPCs associated with class: VM\_metrics} @@ -4131,6 +4132,38 @@ Get the VCPUs/utilisation field of the given VM\_metrics. } +value of the field +\vspace{0.3cm} +\vspace{0.3cm} +\vspace{0.3cm} +\subsubsection{RPC name:~get\_last\_updated} + +{\bf Overview:} +Get the last\_updated field of the given VM\_metrics. + + \noindent {\bf Signature:} +\begin{verbatim} datetime get_last_updated (session_id s, VM_metrics ref self)\end{verbatim} + + +\noindent{\bf Arguments:} + + +\vspace{0.3cm} +\begin{tabular}{|c|c|p{7cm}|} + \hline +{\bf type} & {\bf name} & {\bf description} \\ \hline +{\tt VM\_metrics ref } & self & reference to the object \\ \hline + +\end{tabular} + +\vspace{0.3cm} + + \noindent {\bf Return Type:} +{\tt +datetime +} + + value of the field \vspace{0.3cm} \vspace{0.3cm} @@ -4219,6 +4252,7 @@ $\mathit{RO}_\mathit{run}$ & {\tt memory} & (string $\rightarrow$ string) Map & $\mathit{RO}_\mathit{run}$ & {\tt disks} & (string $\rightarrow$ string) Map & disk configuration/free space \\ $\mathit{RO}_\mathit{run}$ & {\tt networks} & (string $\rightarrow$ string) Map & network configuration \\ $\mathit{RO}_\mathit{run}$ & {\tt other} & (string $\rightarrow$ string) Map & anything else \\ +$\mathit{RO}_\mathit{run}$ & {\tt last\_updated} & datetime & Time at which this information was last updated \\ \hline \end{longtable} \subsection{RPCs associated with class: VM\_guest\_metrics} @@ -4463,6 +4497,38 @@ Get the other field of the given VM\_guest\_metrics. } +value of the field +\vspace{0.3cm} +\vspace{0.3cm} +\vspace{0.3cm} +\subsubsection{RPC name:~get\_last\_updated} + +{\bf Overview:} +Get the last\_updated field of the given VM\_guest\_metrics. + + \noindent {\bf Signature:} +\begin{verbatim} datetime get_last_updated (session_id s, VM_guest_metrics ref self)\end{verbatim} + + +\noindent{\bf Arguments:} + + +\vspace{0.3cm} +\begin{tabular}{|c|c|p{7cm}|} + \hline +{\bf type} & {\bf name} & {\bf description} \\ \hline +{\tt VM\_guest\_metrics ref } & self & reference to the object \\ \hline + +\end{tabular} + +\vspace{0.3cm} + + \noindent {\bf Return Type:} +{\tt +datetime +} + + value of the field \vspace{0.3cm} \vspace{0.3cm} @@ -5816,6 +5882,7 @@ Quals & Field & Type & Description \\ $\mathit{RO}_\mathit{run}$ & {\tt uuid} & string & unique identifier/object reference \\ $\mathit{RO}_\mathit{run}$ & {\tt memory/total} & int & Host's total memory (bytes) \\ $\mathit{RO}_\mathit{run}$ & {\tt memory/free} & int & Host's free memory (bytes) \\ +$\mathit{RO}_\mathit{run}$ & {\tt last\_updated} & datetime & Time at which this information was last updated \\ \hline \end{longtable} \subsection{RPCs associated with class: host\_metrics} @@ -5932,6 +5999,38 @@ int } +value of the field +\vspace{0.3cm} +\vspace{0.3cm} +\vspace{0.3cm} +\subsubsection{RPC name:~get\_last\_updated} + +{\bf Overview:} +Get the last\_updated field of the given host\_metrics. + + \noindent {\bf Signature:} +\begin{verbatim} datetime get_last_updated (session_id s, host_metrics ref self)\end{verbatim} + + +\noindent{\bf Arguments:} + + +\vspace{0.3cm} +\begin{tabular}{|c|c|p{7cm}|} + \hline +{\bf type} & {\bf name} & {\bf description} \\ \hline +{\tt host\_metrics ref } & self & reference to the object \\ \hline + +\end{tabular} + +\vspace{0.3cm} + + \noindent {\bf Return Type:} +{\tt +datetime +} + + value of the field \vspace{0.3cm} \vspace{0.3cm} @@ -7745,6 +7844,7 @@ Quals & Field & Type & Description \\ $\mathit{RO}_\mathit{run}$ & {\tt uuid} & string & unique identifier/object reference \\ $\mathit{RO}_\mathit{run}$ & {\tt io/read\_kbs} & float & Read bandwidth (KiB/s) \\ $\mathit{RO}_\mathit{run}$ & {\tt io/write\_kbs} & float & Write bandwidth (KiB/s) \\ +$\mathit{RO}_\mathit{run}$ & {\tt last\_updated} & datetime & Time at which this information was last updated \\ \hline \end{longtable} \subsection{RPCs associated with class: VIF\_metrics} @@ -7861,6 +7961,38 @@ float } +value of the field +\vspace{0.3cm} +\vspace{0.3cm} +\vspace{0.3cm} +\subsubsection{RPC name:~get\_last\_updated} + +{\bf Overview:} +Get the last\_updated field of the given VIF\_metrics. + + \noindent {\bf Signature:} +\begin{verbatim} datetime get_last_updated (session_id s, VIF_metrics ref self)\end{verbatim} + + +\noindent{\bf Arguments:} + + +\vspace{0.3cm} +\begin{tabular}{|c|c|p{7cm}|} + \hline +{\bf type} & {\bf name} & {\bf description} \\ \hline +{\tt VIF\_metrics ref } & self & reference to the object \\ \hline + +\end{tabular} + +\vspace{0.3cm} + + \noindent {\bf Return Type:} +{\tt +datetime +} + + value of the field \vspace{0.3cm} \vspace{0.3cm} @@ -8522,6 +8654,7 @@ Quals & Field & Type & Description \\ $\mathit{RO}_\mathit{run}$ & {\tt uuid} & string & unique identifier/object reference \\ $\mathit{RO}_\mathit{run}$ & {\tt io/read\_kbs} & float & Read bandwidth (KiB/s) \\ $\mathit{RO}_\mathit{run}$ & {\tt io/write\_kbs} & float & Write bandwidth (KiB/s) \\ +$\mathit{RO}_\mathit{run}$ & {\tt last\_updated} & datetime & Time at which this information was last updated \\ \hline \end{longtable} \subsection{RPCs associated with class: PIF\_metrics} @@ -8638,6 +8771,38 @@ float } +value of the field +\vspace{0.3cm} +\vspace{0.3cm} +\vspace{0.3cm} +\subsubsection{RPC name:~get\_last\_updated} + +{\bf Overview:} +Get the last\_updated field of the given PIF\_metrics. + + \noindent {\bf Signature:} +\begin{verbatim} datetime get_last_updated (session_id s, PIF_metrics ref self)\end{verbatim} + + +\noindent{\bf Arguments:} + + +\vspace{0.3cm} +\begin{tabular}{|c|c|p{7cm}|} + \hline +{\bf type} & {\bf name} & {\bf description} \\ \hline +{\tt PIF\_metrics ref } & self & reference to the object \\ \hline + +\end{tabular} + +\vspace{0.3cm} + + \noindent {\bf Return Type:} +{\tt +datetime +} + + value of the field \vspace{0.3cm} \vspace{0.3cm} @@ -11293,6 +11458,7 @@ Quals & Field & Type & Description \\ $\mathit{RO}_\mathit{run}$ & {\tt uuid} & string & unique identifier/object reference \\ $\mathit{RO}_\mathit{run}$ & {\tt io/read\_kbs} & float & Read bandwidth (KiB/s) \\ $\mathit{RO}_\mathit{run}$ & {\tt io/write\_kbs} & float & Write bandwidth (KiB/s) \\ +$\mathit{RO}_\mathit{run}$ & {\tt last\_updated} & datetime & Time at which this information was last updated \\ \hline \end{longtable} \subsection{RPCs associated with class: VBD\_metrics} @@ -11409,6 +11575,38 @@ float } +value of the field +\vspace{0.3cm} +\vspace{0.3cm} +\vspace{0.3cm} +\subsubsection{RPC name:~get\_last\_updated} + +{\bf Overview:} +Get the last\_updated field of the given VBD\_metrics. + + \noindent {\bf Signature:} +\begin{verbatim} datetime get_last_updated (session_id s, VBD_metrics ref self)\end{verbatim} + + +\noindent{\bf Arguments:} + + +\vspace{0.3cm} +\begin{tabular}{|c|c|p{7cm}|} + \hline +{\bf type} & {\bf name} & {\bf description} \\ \hline +{\tt VBD\_metrics ref } & self & reference to the object \\ \hline + +\end{tabular} + +\vspace{0.3cm} + + \noindent {\bf Return Type:} +{\tt +datetime +} + + value of the field \vspace{0.3cm} \vspace{0.3cm} diff --git a/tools/libxen/include/xen_host_metrics.h b/tools/libxen/include/xen_host_metrics.h index 31f3123364..84121332c7 100644 --- a/tools/libxen/include/xen_host_metrics.h +++ b/tools/libxen/include/xen_host_metrics.h @@ -64,6 +64,7 @@ typedef struct xen_host_metrics_record char *uuid; int64_t memory_total; int64_t memory_free; + time_t last_updated; } xen_host_metrics_record; /** @@ -181,6 +182,13 @@ extern bool xen_host_metrics_get_memory_free(xen_session *session, int64_t *result, xen_host_metrics host_metrics); +/** + * Get the last_updated field of the given host_metrics. + */ +extern bool +xen_host_metrics_get_last_updated(xen_session *session, time_t *result, xen_host_metrics host_metrics); + + /** * Return a list of all the host_metrics instances known to the system. */ diff --git a/tools/libxen/include/xen_pif_metrics.h b/tools/libxen/include/xen_pif_metrics.h index b8dad22afa..970700feb1 100644 --- a/tools/libxen/include/xen_pif_metrics.h +++ b/tools/libxen/include/xen_pif_metrics.h @@ -64,6 +64,7 @@ typedef struct xen_pif_metrics_record char *uuid; double io_read_kbs; double io_write_kbs; + time_t last_updated; } xen_pif_metrics_record; /** @@ -180,6 +181,13 @@ extern bool xen_pif_metrics_get_io_write_kbs(xen_session *session, double *result, xen_pif_metrics pif_metrics); +/** + * Get the last_updated field of the given PIF_metrics. + */ +extern bool +xen_pif_metrics_get_last_updated(xen_session *session, time_t *result, xen_pif_metrics pif_metrics); + + /** * Return a list of all the PIF_metrics instances known to the system. */ diff --git a/tools/libxen/include/xen_vbd_metrics.h b/tools/libxen/include/xen_vbd_metrics.h index 3cd507b31e..f1aa420a34 100644 --- a/tools/libxen/include/xen_vbd_metrics.h +++ b/tools/libxen/include/xen_vbd_metrics.h @@ -64,6 +64,7 @@ typedef struct xen_vbd_metrics_record char *uuid; double io_read_kbs; double io_write_kbs; + time_t last_updated; } xen_vbd_metrics_record; /** @@ -180,6 +181,13 @@ extern bool xen_vbd_metrics_get_io_write_kbs(xen_session *session, double *result, xen_vbd_metrics vbd_metrics); +/** + * Get the last_updated field of the given VBD_metrics. + */ +extern bool +xen_vbd_metrics_get_last_updated(xen_session *session, time_t *result, xen_vbd_metrics vbd_metrics); + + /** * Return a list of all the VBD_metrics instances known to the system. */ diff --git a/tools/libxen/include/xen_vif_metrics.h b/tools/libxen/include/xen_vif_metrics.h index b5a26f25c6..2febab468d 100644 --- a/tools/libxen/include/xen_vif_metrics.h +++ b/tools/libxen/include/xen_vif_metrics.h @@ -64,6 +64,7 @@ typedef struct xen_vif_metrics_record char *uuid; double io_read_kbs; double io_write_kbs; + time_t last_updated; } xen_vif_metrics_record; /** @@ -180,6 +181,13 @@ extern bool xen_vif_metrics_get_io_write_kbs(xen_session *session, double *result, xen_vif_metrics vif_metrics); +/** + * Get the last_updated field of the given VIF_metrics. + */ +extern bool +xen_vif_metrics_get_last_updated(xen_session *session, time_t *result, xen_vif_metrics vif_metrics); + + /** * Return a list of all the VIF_metrics instances known to the system. */ diff --git a/tools/libxen/include/xen_vm_guest_metrics.h b/tools/libxen/include/xen_vm_guest_metrics.h index 61b8b5b2b7..2734764526 100644 --- a/tools/libxen/include/xen_vm_guest_metrics.h +++ b/tools/libxen/include/xen_vm_guest_metrics.h @@ -69,6 +69,7 @@ typedef struct xen_vm_guest_metrics_record xen_string_string_map *disks; xen_string_string_map *networks; xen_string_string_map *other; + time_t last_updated; } xen_vm_guest_metrics_record; /** @@ -215,6 +216,13 @@ extern bool xen_vm_guest_metrics_get_other(xen_session *session, xen_string_string_map **result, xen_vm_guest_metrics vm_guest_metrics); +/** + * Get the last_updated field of the given VM_guest_metrics. + */ +extern bool +xen_vm_guest_metrics_get_last_updated(xen_session *session, time_t *result, xen_vm_guest_metrics vm_guest_metrics); + + /** * Return a list of all the VM_guest_metrics instances known to the * system. diff --git a/tools/libxen/include/xen_vm_metrics.h b/tools/libxen/include/xen_vm_metrics.h index b03c4d4e3c..d686a7c99f 100644 --- a/tools/libxen/include/xen_vm_metrics.h +++ b/tools/libxen/include/xen_vm_metrics.h @@ -66,6 +66,7 @@ typedef struct xen_vm_metrics_record int64_t memory_actual; int64_t vcpus_number; xen_int_float_map *vcpus_utilisation; + time_t last_updated; } xen_vm_metrics_record; /** @@ -189,6 +190,13 @@ extern bool xen_vm_metrics_get_vcpus_utilisation(xen_session *session, xen_int_float_map **result, xen_vm_metrics vm_metrics); +/** + * Get the last_updated field of the given VM_metrics. + */ +extern bool +xen_vm_metrics_get_last_updated(xen_session *session, time_t *result, xen_vm_metrics vm_metrics); + + /** * Return a list of all the VM_metrics instances known to the system. */ diff --git a/tools/libxen/src/xen_host_metrics.c b/tools/libxen/src/xen_host_metrics.c index d82994dfd0..bc621fbaae 100644 --- a/tools/libxen/src/xen_host_metrics.c +++ b/tools/libxen/src/xen_host_metrics.c @@ -44,7 +44,10 @@ static const struct_member xen_host_metrics_record_struct_members[] = .offset = offsetof(xen_host_metrics_record, memory_total) }, { .key = "memory_free", .type = &abstract_type_int, - .offset = offsetof(xen_host_metrics_record, memory_free) } + .offset = offsetof(xen_host_metrics_record, memory_free) }, + { .key = "last_updated", + .type = &abstract_type_datetime, + .offset = offsetof(xen_host_metrics_record, last_updated) } }; const abstract_type xen_host_metrics_record_abstract_type_ = @@ -142,6 +145,22 @@ xen_host_metrics_get_memory_free(xen_session *session, int64_t *result, xen_host } +bool +xen_host_metrics_get_last_updated(xen_session *session, time_t *result, xen_host_metrics host_metrics) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = host_metrics } + }; + + abstract_type result_type = abstract_type_datetime; + + XEN_CALL_("host_metrics.get_last_updated"); + return session->ok; +} + + bool xen_host_metrics_get_all(xen_session *session, struct xen_host_metrics_set **result) { diff --git a/tools/libxen/src/xen_pif_metrics.c b/tools/libxen/src/xen_pif_metrics.c index 65e3e22f3b..5826001731 100644 --- a/tools/libxen/src/xen_pif_metrics.c +++ b/tools/libxen/src/xen_pif_metrics.c @@ -44,7 +44,10 @@ static const struct_member xen_pif_metrics_record_struct_members[] = .offset = offsetof(xen_pif_metrics_record, io_read_kbs) }, { .key = "io_write_kbs", .type = &abstract_type_float, - .offset = offsetof(xen_pif_metrics_record, io_write_kbs) } + .offset = offsetof(xen_pif_metrics_record, io_write_kbs) }, + { .key = "last_updated", + .type = &abstract_type_datetime, + .offset = offsetof(xen_pif_metrics_record, last_updated) } }; const abstract_type xen_pif_metrics_record_abstract_type_ = @@ -142,6 +145,22 @@ xen_pif_metrics_get_io_write_kbs(xen_session *session, double *result, xen_pif_m } +bool +xen_pif_metrics_get_last_updated(xen_session *session, time_t *result, xen_pif_metrics pif_metrics) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = pif_metrics } + }; + + abstract_type result_type = abstract_type_datetime; + + XEN_CALL_("PIF_metrics.get_last_updated"); + return session->ok; +} + + bool xen_pif_metrics_get_all(xen_session *session, struct xen_pif_metrics_set **result) { diff --git a/tools/libxen/src/xen_vbd_metrics.c b/tools/libxen/src/xen_vbd_metrics.c index 985553d5a0..f0b221f65e 100644 --- a/tools/libxen/src/xen_vbd_metrics.c +++ b/tools/libxen/src/xen_vbd_metrics.c @@ -44,7 +44,10 @@ static const struct_member xen_vbd_metrics_record_struct_members[] = .offset = offsetof(xen_vbd_metrics_record, io_read_kbs) }, { .key = "io_write_kbs", .type = &abstract_type_float, - .offset = offsetof(xen_vbd_metrics_record, io_write_kbs) } + .offset = offsetof(xen_vbd_metrics_record, io_write_kbs) }, + { .key = "last_updated", + .type = &abstract_type_datetime, + .offset = offsetof(xen_vbd_metrics_record, last_updated) } }; const abstract_type xen_vbd_metrics_record_abstract_type_ = @@ -142,6 +145,22 @@ xen_vbd_metrics_get_io_write_kbs(xen_session *session, double *result, xen_vbd_m } +bool +xen_vbd_metrics_get_last_updated(xen_session *session, time_t *result, xen_vbd_metrics vbd_metrics) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = vbd_metrics } + }; + + abstract_type result_type = abstract_type_datetime; + + XEN_CALL_("VBD_metrics.get_last_updated"); + return session->ok; +} + + bool xen_vbd_metrics_get_all(xen_session *session, struct xen_vbd_metrics_set **result) { diff --git a/tools/libxen/src/xen_vif_metrics.c b/tools/libxen/src/xen_vif_metrics.c index 78707b36f5..b3b2a79f59 100644 --- a/tools/libxen/src/xen_vif_metrics.c +++ b/tools/libxen/src/xen_vif_metrics.c @@ -44,7 +44,10 @@ static const struct_member xen_vif_metrics_record_struct_members[] = .offset = offsetof(xen_vif_metrics_record, io_read_kbs) }, { .key = "io_write_kbs", .type = &abstract_type_float, - .offset = offsetof(xen_vif_metrics_record, io_write_kbs) } + .offset = offsetof(xen_vif_metrics_record, io_write_kbs) }, + { .key = "last_updated", + .type = &abstract_type_datetime, + .offset = offsetof(xen_vif_metrics_record, last_updated) } }; const abstract_type xen_vif_metrics_record_abstract_type_ = @@ -142,6 +145,22 @@ xen_vif_metrics_get_io_write_kbs(xen_session *session, double *result, xen_vif_m } +bool +xen_vif_metrics_get_last_updated(xen_session *session, time_t *result, xen_vif_metrics vif_metrics) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = vif_metrics } + }; + + abstract_type result_type = abstract_type_datetime; + + XEN_CALL_("VIF_metrics.get_last_updated"); + return session->ok; +} + + bool xen_vif_metrics_get_all(xen_session *session, struct xen_vif_metrics_set **result) { diff --git a/tools/libxen/src/xen_vm_guest_metrics.c b/tools/libxen/src/xen_vm_guest_metrics.c index dd464c4806..f18966c46a 100644 --- a/tools/libxen/src/xen_vm_guest_metrics.c +++ b/tools/libxen/src/xen_vm_guest_metrics.c @@ -57,7 +57,10 @@ static const struct_member xen_vm_guest_metrics_record_struct_members[] = .offset = offsetof(xen_vm_guest_metrics_record, networks) }, { .key = "other", .type = &abstract_type_string_string_map, - .offset = offsetof(xen_vm_guest_metrics_record, other) } + .offset = offsetof(xen_vm_guest_metrics_record, other) }, + { .key = "last_updated", + .type = &abstract_type_datetime, + .offset = offsetof(xen_vm_guest_metrics_record, last_updated) } }; const abstract_type xen_vm_guest_metrics_record_abstract_type_ = @@ -231,6 +234,22 @@ xen_vm_guest_metrics_get_other(xen_session *session, xen_string_string_map **res } +bool +xen_vm_guest_metrics_get_last_updated(xen_session *session, time_t *result, xen_vm_guest_metrics vm_guest_metrics) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = vm_guest_metrics } + }; + + abstract_type result_type = abstract_type_datetime; + + XEN_CALL_("VM_guest_metrics.get_last_updated"); + return session->ok; +} + + bool xen_vm_guest_metrics_get_all(xen_session *session, struct xen_vm_guest_metrics_set **result) { diff --git a/tools/libxen/src/xen_vm_metrics.c b/tools/libxen/src/xen_vm_metrics.c index 9bafa83aa0..ae20899e06 100644 --- a/tools/libxen/src/xen_vm_metrics.c +++ b/tools/libxen/src/xen_vm_metrics.c @@ -48,7 +48,10 @@ static const struct_member xen_vm_metrics_record_struct_members[] = .offset = offsetof(xen_vm_metrics_record, vcpus_number) }, { .key = "VCPUs_utilisation", .type = &abstract_type_int_float_map, - .offset = offsetof(xen_vm_metrics_record, vcpus_utilisation) } + .offset = offsetof(xen_vm_metrics_record, vcpus_utilisation) }, + { .key = "last_updated", + .type = &abstract_type_datetime, + .offset = offsetof(xen_vm_metrics_record, last_updated) } }; const abstract_type xen_vm_metrics_record_abstract_type_ = @@ -164,6 +167,22 @@ xen_vm_metrics_get_vcpus_utilisation(xen_session *session, xen_int_float_map **r } +bool +xen_vm_metrics_get_last_updated(xen_session *session, time_t *result, xen_vm_metrics vm_metrics) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = vm_metrics } + }; + + abstract_type result_type = abstract_type_datetime; + + XEN_CALL_("VM_metrics.get_last_updated"); + return session->ok; +} + + bool xen_vm_metrics_get_all(xen_session *session, struct xen_vm_metrics_set **result) { diff --git a/tools/libxen/test/test_bindings.c b/tools/libxen/test/test_bindings.c index 1471814d81..c709e64867 100644 --- a/tools/libxen/test/test_bindings.c +++ b/tools/libxen/test/test_bindings.c @@ -592,6 +592,11 @@ static void print_vm_metrics(xen_session *session, xen_vm vm) return; } + char time[256]; + struct tm *tm = localtime(&vm_metrics_record->last_updated); + strftime(time, 256, "Metrics updated at %c, local time.\n", tm); + printf(time); + for (size_t i = 0; i < vm_metrics_record->vcpus_utilisation->size; i++) { printf("%"PRId64" -> %lf.\n", diff --git a/tools/python/xen/xend/XendAPI.py b/tools/python/xen/xend/XendAPI.py index 4c2ba32ae0..e2a0a78b60 100644 --- a/tools/python/xen/xend/XendAPI.py +++ b/tools/python/xen/xend/XendAPI.py @@ -21,6 +21,8 @@ import string import sys import traceback import threading +import time +import xmlrpclib from xen.xend import XendDomain, XendDomainInfo, XendNode, XendDmesg from xen.xend import XendLogging, XendTaskManager @@ -77,6 +79,11 @@ def xen_api_todo(): """Temporary method to make sure we track down all the TODOs""" return {"Status": "Error", "ErrorDescription": XEND_ERROR_TODO} + +def now(): + return xmlrpclib.DateTime(time.strftime("%Y%m%dT%H:%M:%S", time.gmtime())) + + # --------------------------------------------------- # Python Method Decorators for input value validation # --------------------------------------------------- @@ -850,7 +857,8 @@ class XendAPI(object): # ---------------------------------------------------------------- host_metrics_attr_ro = ['memory_total', - 'memory_free'] + 'memory_free', + 'last_updated'] host_metrics_attr_rw = [] host_metrics_methods = [] @@ -865,14 +873,18 @@ class XendAPI(object): 'uuid' : ref, 'memory_total' : self._host_metrics_get_memory_total(), 'memory_free' : self._host_metrics_get_memory_free(), + 'last_updated' : now(), }) - def host_metrics_get_memory_total(self, _, ref): + def host_metrics_get_memory_total(self, _1, _2): return xen_api_success(self._host_metrics_get_memory_total()) - def host_metrics_get_memory_free(self, _, ref): + def host_metrics_get_memory_free(self, _1, _2): return xen_api_success(self._host_metrics_get_memory_free()) + def host_metrics_get_last_updated(self, _1, _2): + return xen_api_success(now()) + def _host_metrics_get_memory_total(self): node = XendNode.instance() return node.xc.physinfo()['total_memory'] * 1024 @@ -1012,7 +1024,8 @@ class XendAPI(object): # ---------------------------------------------------------------- PIF_metrics_attr_ro = ['io_read_kbs', - 'io_write_kbs'] + 'io_write_kbs', + 'last_updated'] PIF_metrics_attr_rw = [] PIF_methods = [] @@ -1031,6 +1044,9 @@ class XendAPI(object): def PIF_metrics_get_io_write_kbs(self, _, ref): return xen_api_success(self._PIF_metrics_get(ref).get_io_write_kbs()) + def PIF_metrics_get_last_updated(self, _1, _2): + return xen_api_success(now()) + # Xen API: Class VM # ---------------------------------------------------------------- @@ -1609,7 +1625,8 @@ class XendAPI(object): 'VCPUs_flags', 'VCPUs_params', 'state', - 'start_time'] + 'start_time', + 'last_updated'] VM_metrics_attr_rw = [] VM_metrics_methods = [] @@ -1646,6 +1663,9 @@ class XendAPI(object): def VM_metrics_get_state(self, _, ref): return xen_api_success(self._VM_metrics_get(ref).get_state()) + def VM_metrics_get_last_updated(self, _1, _2): + return xen_api_success(now()) + # Xen API: Class VBD # ---------------------------------------------------------------- @@ -1800,7 +1820,8 @@ class XendAPI(object): # ---------------------------------------------------------------- VBD_metrics_attr_ro = ['io_read_kbs', - 'io_write_kbs'] + 'io_write_kbs', + 'last_updated'] VBD_metrics_attr_rw = [] VBD_methods = [] @@ -1810,7 +1831,9 @@ class XendAPI(object): return xen_api_error(['HANDLE_INVALID', 'VBD_metrics', ref]) return xen_api_success( { 'io_read_kbs' : vm.get_dev_property('vbd', ref, 'io_read_kbs'), - 'io_write_kbs' : vm.get_dev_property('vbd', ref, 'io_write_kbs') }) + 'io_write_kbs' : vm.get_dev_property('vbd', ref, 'io_write_kbs'), + 'last_updated' : now() + }) def VBD_metrics_get_io_read_kbs(self, _, ref): return self._VBD_get(ref, 'io_read_kbs') @@ -1818,6 +1841,9 @@ class XendAPI(object): def VBD_metrics_get_io_write_kbs(self, session, ref): return self._VBD_get(ref, 'io_write_kbs') + def VBD_metrics_get_last_updated(self, _1, _2): + return xen_api_success(now()) + # Xen API: Class VIF # ---------------------------------------------------------------- @@ -1934,7 +1960,8 @@ class XendAPI(object): # ---------------------------------------------------------------- VIF_metrics_attr_ro = ['io_read_kbs', - 'io_write_kbs'] + 'io_write_kbs', + 'last_updated'] VIF_metrics_attr_rw = [] VIF_methods = [] @@ -1944,7 +1971,9 @@ class XendAPI(object): return xen_api_error(['HANDLE_INVALID', 'VIF_metrics', ref]) return xen_api_success( { 'io_read_kbs' : vm.get_dev_property('vif', ref, 'io_read_kbs'), - 'io_write_kbs' : vm.get_dev_property('vif', ref, 'io_write_kbs') }) + 'io_write_kbs' : vm.get_dev_property('vif', ref, 'io_write_kbs'), + 'last_updated' : now() + }) def VIF_metrics_get_io_read_kbs(self, _, ref): return self._VIF_get(ref, 'io_read_kbs') @@ -1952,6 +1981,9 @@ class XendAPI(object): def VIF_metrics_get_io_write_kbs(self, session, ref): return self._VIF_get(ref, 'io_write_kbs') + def VIF_metrics_get_last_updated(self, _1, _2): + return xen_api_success(now()) + # Xen API: Class VDI # ---------------------------------------------------------------- @@ -2424,39 +2456,3 @@ class XendAPIAsyncProxy: synchronous_method_name, session) return xen_api_success(task_uuid) - -# -# Auto generate some stubs based on XendAPI introspection -# -if __name__ == "__main__": - def output(line): - print ' ' + line - - classes = ['VDI', 'SR'] - for cls in classes: - ro_attrs = getattr(XendAPI, '%s_attr_ro' % cls, []) - rw_attrs = getattr(XendAPI, '%s_attr_rw' % cls, []) - methods = getattr(XendAPI, '%s_methods' % cls, []) - funcs = getattr(XendAPI, '%s_funcs' % cls, []) - - ref = '%s_ref' % cls - - for attr_name in ro_attrs + rw_attrs + XendAPI.Base_attr_ro: - getter_name = '%s_get_%s' % (cls, attr_name) - output('def %s(self, session, %s):' % (getter_name, ref)) - output(' return xen_api_todo()') - - for attr_name in rw_attrs + XendAPI.Base_attr_rw: - setter_name = '%s_set_%s' % (cls, attr_name) - output('def %s(self, session, %s, value):' % (setter_name, ref)) - output(' return xen_api_todo()') - - for method_name in methods + XendAPI.Base_methods: - method_full_name = '%s_%s' % (cls,method_name) - output('def %s(self, session, %s):' % (method_full_name, ref)) - output(' return xen_api_todo()') - - for func_name in funcs + XendAPI.Base_funcs: - func_full_name = '%s_%s' % (cls, func_name) - output('def %s(self, session):' % func_full_name) - output(' return xen_api_todo()') diff --git a/tools/python/xen/xend/XendPIFMetrics.py b/tools/python/xen/xend/XendPIFMetrics.py index 8c65251664..36a1e582f4 100644 --- a/tools/python/xen/xend/XendPIFMetrics.py +++ b/tools/python/xen/xend/XendPIFMetrics.py @@ -40,8 +40,10 @@ class XendPIFMetrics: return 0.0 def get_record(self): + import xen.xend.XendAPI as XendAPI return {'uuid' : self.uuid, 'PIF' : self.pif.uuid, 'io_read_kbs' : self.get_io_read_kbs(), - 'io_write_kbs' : self.get_io_write_kbs() + 'io_write_kbs' : self.get_io_write_kbs(), + 'last_updated' : XendAPI.now(), } diff --git a/tools/python/xen/xend/XendVMMetrics.py b/tools/python/xen/xend/XendVMMetrics.py index 2ba328a5cd..9daee212ce 100644 --- a/tools/python/xen/xend/XendVMMetrics.py +++ b/tools/python/xen/xend/XendVMMetrics.py @@ -141,6 +141,7 @@ class XendVMMetrics: return self.xend_domain_instance.info.get("start_time", -1) def get_record(self): + import xen.xend.XendAPI as XendAPI return { 'uuid' : self.uuid, 'memory_actual' : self.get_memory_actual(), 'VCPUs_number' : self.get_VCPUs_number(), @@ -150,4 +151,5 @@ class XendVMMetrics: 'VCPUs_params' : self.get_VCPUs_params(), 'start_time' : self.get_start_time(), 'state' : self.get_state(), + 'last_updated' : XendAPI.now(), } -- 2.30.2